package org.hgvc.webapp.ets.jsf.beans.admin;

import java.util.List;

import org.hgvc.webapp.ets.bo.Member;
import org.hgvc.webapp.ets.bo.MemberComp;
import org.hgvc.webapp.ets.bo.MemberInd;
import org.hgvc.webapp.ets.bo.MemberIndAcct;
import org.hgvc.webapp.ets.constant.CommonConstant;
import org.hgvc.webapp.ets.constant.MemberConstant;
import org.hgvc.webapp.ets.spring.service.MemberService;
import org.jocsb.base.AbstractBean;
import org.jocsb.base.exception.BaseException;



public class AdminMemberConversionBean extends AbstractBean {
	public static final String BEAN_NAME="adminMemberConversionBean";
	public static final String NAV_CONVERT_IND_ACTION="adminIndMemberCon";
	public static final String NAV_CONVERT_COMP_ACTION="adminCompMemberCon";
	private Member member;
	private MemberComp memberComp;
	private MemberInd memberInd;
	private MemberService service;
	private List<MemberIndAcct> list;

	public Member getMember() {
		return member;
	}
	public void setMember(Member member) {
		this.member = member;
	}
	public MemberComp getMemberComp() {
		return memberComp;
	}
	public void setMemberComp(MemberComp memberComp) {
		this.memberComp = memberComp;
	}
	public MemberInd getMemberInd() {
		return memberInd;
	}
	public void setMemberInd(MemberInd memberInd) {
		this.memberInd = memberInd;
	}
	public void setService(MemberService service) {
		this.service = service;
	}
	public List<MemberIndAcct> getList() {
		return list;
	}
	public void setList(List<MemberIndAcct> list) {
		this.list = list;
	}
	/*----------------------------------------------------------*/
	public String navMemberConversionAction(Member member){
		try{
			this.member = member;
			this.member.setMembershipNo(service.generatePreMembershipNo(member));
			if(member.getMemberType().equalsIgnoreCase(CommonConstant.MEMBER_TYPE_COMP)){
				memberComp = service.getMemberCompByMemberId(member.getMemberId());
				list = service.getMemberIndAcctByMemberComp(memberComp.getMemberCompId());
				return NAV_CONVERT_COMP_ACTION.concat("_"+getRoleName());
			}else{
				memberInd = service.getMemberIndByMemberId(member.getMemberId());
				list = service.getMemberIndAcctByMemberInd(memberInd.getMemberIndId());				
				return NAV_CONVERT_IND_ACTION.concat("_"+getRoleName());
			}
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return null;
	}
	
	public String convertAction(){
		try{
			service.memberConversion(member, getThisUser());
			return AdminProspectMagmtBean.NAV_LIST.concat("_"+getRoleName());
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return null;
	}
	
	public String backAction(){
		return AdminProspectMagmtBean.NAV_LIST.concat("_"+getRoleName());
	}
}
